package com.s63.ssm.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.s63.ssm.entity.SysRole;
import com.s63.ssm.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/roles")
@Controller
public class RoleController extends BaseController {
    @Autowired
    private RoleService roleService;

    @GetMapping("/getAll")
    @ResponseBody
    public List<SysRole> getAll() {
        return roleService.getAll();
    }



    @RequestMapping("/list")
    public String getPage(SysRole role, Integer pageNo, Integer pageSize, Model model) {
        if (pageNo == null) pageNo = 1;
        if (pageSize == null) pageSize = 2;

        PageHelper.startPage(pageNo, pageSize);
        List<SysRole> list = roleService.getPage(role);
        PageInfo<SysRole> pageInfo = PageInfo.of(list);

        model.addAttribute("page", pageInfo);
        model.addAttribute("role", role);
        System.out.println("pageInfo = " + pageInfo);
        return "role/list";
    }
}
